package com.lmy.springCloud.service;

import com.lmy.springCloud.entity.Member;
import com.lmy.springCloud.utils.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 使用@FeignClient(value = "")指定在nacos server注册的要远程调用的服务名称
 */
@Component
@FeignClient(value = "member-service-nacos-provider", fallback = MemberOpenFeignFallbackService.class)
public interface MemberOpenFeignService {

    /**
     * 1.远程调用方式是get
     * 2.远程调用的url 为 http://member-service-nacos-provider/getMemberById/{id}
     * 3.member-service-nacos-provider 是 在nacos注册中心注册的一个服务名
     * 4.openFeign会根据负载均衡算法来决定调用10090 还是 10091 服务，默认是轮询算法
     * 5.openFeign是通过接口方式调用远程服务的
     * 6.openFeign默认超时时间1s，即等待结果返回1s
     * @param id
     * @return
     */
    @RequestMapping(value = "/getMemberById/{id}", method = RequestMethod.GET)
    public Result<Member> getMemberById(@PathVariable(value = "id") Long id);

    @RequestMapping(value = "/saveMember", method = RequestMethod.POST)
    public Result saveMember(@RequestBody Member member);
}
